Skip to content

Conversation

@xgupta
Copy link

@xgupta xgupta commented Jun 8, 2024

This PR address the issue reported by static analyser cppcheck regarding missing bounds check for extra iterator increment in a loop. This could lead to accessing out-of-bounds memory.
To fix this we check next of c there is alteast one element left.

Caught by cppcheck -
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp:1300:75: warning: Missing bounds check for extra iterator increment in loop. [StlMissingComparison]

Fix #91225

… in ExpandRLE (NFC)

Address the issue reported by static analyser cppcheck regarding missing bounds check for extra iterator increment in a loop.
This could lead to accessing out-of-bounds memory. To fix this we have adjusted the loop conditions to not incrementing iterator c there..

Caught by cppcheck -
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp:1300:75: warning: Missing bounds check for extra iterator increment in loop. [StlMissingComparison]

Fix llvm#91225
@xgupta xgupta requested a review from JDevlieghere as a code owner June 8, 2024 06:30
@llvmbot llvmbot added the lldb label Jun 8, 2024
@llvmbot
Copy link
Member

llvmbot commented Jun 8, 2024

@llvm/pr-subscribers-lldb

Author: Shivam Gupta (xgupta)

Changes

This PR address the issue reported by static analyser cppcheck regarding missing bounds check for extra iterator increment in a loop. This could lead to accessing out-of-bounds memory.
To fix this we have adjusted the loop conditions to not incrementing iterator c there.

Caught by cppcheck -
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp:1300:75: warning: Missing bounds check for extra iterator increment in loop. [StlMissingComparison]

Fix #91225


Full diff: https://github.com/llvm/llvm-project/pull/94844.diff

1 Files Affected:

  • (modified) lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp (+2-1)
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
index 8a47eed3d7cbe..81644d6248a83 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -1297,7 +1297,7 @@ std::string GDBRemoteCommunication::ExpandRLE(std::string packet) {
   // Reserve enough byte for the most common case (no RLE used).
   std::string decoded;
   decoded.reserve(packet.size());
-  for (std::string::const_iterator c = packet.begin(); c != packet.end(); ++c) {
+  for (std::string::const_iterator c = packet.begin(); c != packet.end();) {
     if (*c == '*') {
       // '*' indicates RLE. Next character will give us the repeat count and
       // previous character is what is to be repeated.
@@ -1316,6 +1316,7 @@ std::string GDBRemoteCommunication::ExpandRLE(std::string packet) {
     } else {
       decoded.push_back(*c);
     }
+    c++;
   }
   return decoded;
 }

@xgupta xgupta requested a review from bulbazord July 27, 2024 01:57
@xgupta
Copy link
Author

xgupta commented Aug 19, 2024

ping!

@xgupta
Copy link
Author

xgupta commented Feb 10, 2025

Could not understand the right fix. Better it to leave it.

@xgupta xgupta closed this Feb 10, 2025
@xgupta xgupta deleted the fix91225 branch February 10, 2025 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp:1300: 2 * missing bounds check ?

4 participants